<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>linux 源代码分析8:Slab内存分配 | 机器人的博客</title>
  <meta name="keywords" content=" linux , 内存管理 , 伙伴系统 , Slab ">
  <meta name="description" content="linux 源代码分析8:Slab内存分配 | 机器人的博客">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="页面未找到！">
<meta property="og:type" content="website">
<meta property="og:title" content="404">
<meta property="og:url" content="http://ancjf.com/404.html">
<meta property="og:site_name" content="机器人的博客">
<meta property="og:description" content="页面未找到！">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-04-18T07:23:22.000Z">
<meta property="article:modified_time" content="2020-04-18T07:23:50.777Z">
<meta property="article:author" content="ancjf">
<meta name="twitter:card" content="summary">


<link rel="icon" href="/img/avatar.jpg">

<link href="/css/style.css?v=1.0.1" rel="stylesheet">

<link href="/css/hl_theme/atom-light.css?v=1.0.1" rel="stylesheet">

<link href="//cdn.bootcss.com/animate.css/3.5.2/animate.min.css" rel="stylesheet">
<link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="/js/jquery.autocomplete.min.js?v=1.0.1" ></script>

<script src="//cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>
<script>
    hljs.initHighlightingOnLoad();
</script>

<script src="//cdn.bootcss.com/nprogress/0.2.0/nprogress.min.js"></script>



<script src="//cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js" ></script>

<script src="/js/iconfont.js?v=1.0.1" ></script>

<meta name="generator" content="Hexo 4.2.0"></head>
<div style="display: none">
  <input class="theme_disqus_on" value="false">
  <input class="theme_preload_comment" value="false">
  <input class="theme_blog_path" value="">
</div>

<body>
<aside class="nav">
    <div class="nav-left">
        <a href="/" class="avatar_target">
    <img class="avatar" src="/img/avatar.jpg" />
</a>
<div class="author">
    <span>ancjf</span>
</div>

<div class="icon">
    
        
        <a title="github" href="https://github.com/ancjf" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-github"></use>
                </svg>
            
        </a>
        
    
        
        <a title="zhihu" href="https://www.zhihu.com/people/ancjf" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-zhihu"></use>
                </svg>
            
        </a>
        
    
        
        <a title="csdn" href="http://blog.csdn.net/ancjf" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-csdn"></use>
                </svg>
            
        </a>
        
    
        
        <a title="email" href="mailto:ancjf@163.com" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-email"></use>
                </svg>
            
        </a>
        
    
        
        <a title="qq" href="http://wpa.qq.com/msgrd?v=3&uin=156715133&site=qq&menu=yes" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-qq"></use>
                </svg>
            
        </a>
        
    
</div>




<ul>
    <li><div class="all active">全部文章<small>(26)</small></div></li>
    
        
            
            <li><div data-rel="linux">linux<small>(12)</small></div>
                
            </li>
            
        
    
        
            
            <li><div data-rel="区块链">区块链<small>(8)</small></div>
                
            </li>
            
        
    
        
            
            <li><div data-rel="c++">c++<small>(4)</small></div>
                
            </li>
            
        
    
        
            
            <li><div data-rel="react native">react native<small>(2)</small></div>
                
            </li>
            
        
    
</ul>
<div class="left-bottom">
    <div class="menus">
    
    
    
    
    </div>
    <div><a class="about  hasFriend  site_url"  href="/about">关于</a><a style="width: 50%"  class="friends">友链</a></div>
</div>
<input type="hidden" id="yelog_site_posts_number" value="26">

<div style="display: none">
    <span id="busuanzi_value_site_uv"></span>
    <span id="busuanzi_value_site_pv"></span>
</div>

    </div>
    <div class="nav-right">
        <div class="friends-area">
    <div class="friends-title">
        友情链接
        <i class="back-title-list"></i>
    </div>
    <div class="friends-content">
        <ul>
            
            <li><a target="_blank" href="http://yelog.org/">叶落阁</a></li>
            
        </ul>
    </div>
</div>
        <div class="title-list">
    <form onkeydown="if(event.keyCode === 13){return false;}">
        <input id="local-search-input" class="search" type="text" placeholder="Search..." />
        <i class="cross"></i>
        <span>
            <label for="tagswitch">Tags:</label>
            <input id="tagswitch" type="checkbox" style="display: none" />
            <i id="tagsWitchIcon"></i>
        </span>
    </form>
    <div class="tags-list">
    
    <li class="article-tag-list-item">
        <a class="color1">linux</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">内存管理</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">伙伴系统</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">内存分配</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">内存释放</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">伙伴系统初始化</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">Slab</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">EOS</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">节点</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">数据备份</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">c语言</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">二分法查找</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">geth</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">私有网络搭建</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">以太坊</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">c++</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">rpc</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">code-push</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">react native</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">样式</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">调试宏</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">DPRINTF</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">DERROR</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">PERR</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">gbk2312，拼音表，排好</a>
    </li>
    
    <div class="clearfix"></div>
</div>

    
    <nav id="title-list-nav">
        
        <a id="top" class="区块链 "
           href="/2018/09/29/EOS-%E8%8A%82%E7%82%B9%E6%95%B0%E6%8D%AE%E5%A4%87%E4%BB%BD/"
           data-tag="EOS,节点,数据备份"
           data-author="" >
            <span class="post-title" title="EOS 节点数据备份">EOS 节点数据备份</span>
            <span class="post-date" title="2018-09-29 21:51:16">2018/09/29</span>
        </a>
        
        <a id="top" class="区块链 "
           href="/2018/07/29/%E4%BB%A5%E5%A4%AA%E5%9D%8A/"
           data-tag="以太坊"
           data-author="" >
            <span class="post-title" title="以太坊">以太坊</span>
            <span class="post-date" title="2018-07-29 20:50:06">2018/07/29</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/05/18/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%901%EF%BC%9A%E6%BA%90%E4%BB%A3%E7%A0%81%E9%98%85%E8%AF%BB%E5%B7%A5%E5%85%B7%EF%BC%8C%E7%BC%96%E8%AF%91%E5%8F%8A%E8%B0%83%E8%AF%95/"
           data-tag="linux,内存管理"
           data-author="" >
            <span class="post-title" title="linux 源代码分析1:源代码阅读工具，编译及调试">linux 源代码分析1:源代码阅读工具，编译及调试</span>
            <span class="post-date" title="2013-05-18 10:18:17">2013/05/18</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/05/19/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%902%EF%BC%9A%E4%BC%99%E4%BC%B4%E7%B3%BB%E7%BB%9F/"
           data-tag="linux,内存管理,伙伴系统"
           data-author="" >
            <span class="post-title" title="linux 源代码分析2:伙伴系统">linux 源代码分析2:伙伴系统</span>
            <span class="post-date" title="2013-05-19 11:08:56">2013/05/19</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/05/20/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%903-%E4%BC%99%E4%BC%B4%E7%B3%BB%E7%BB%9F%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D/"
           data-tag="linux,内存管理,伙伴系统,内存分配"
           data-author="" >
            <span class="post-title" title="linux 源代码分析3:伙伴系统内存分配">linux 源代码分析3:伙伴系统内存分配</span>
            <span class="post-date" title="2013-05-20 19:29:04">2013/05/20</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/05/21/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%904-%E4%BC%99%E4%BC%B4%E7%B3%BB%E7%BB%9F%E5%86%85%E5%AD%98%E9%87%8A%E6%94%BE/"
           data-tag="linux,内存管理,伙伴系统,内存释放"
           data-author="" >
            <span class="post-title" title="linux 源代码分析4:伙伴系统内存释放">linux 源代码分析4:伙伴系统内存释放</span>
            <span class="post-date" title="2013-05-21 20:25:33">2013/05/21</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/05/22/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%905-%E4%BC%99%E4%BC%B4%E7%B3%BB%E7%BB%9F%E5%88%9D%E5%A7%8B%E5%8C%96/"
           data-tag="linux,内存管理,伙伴系统,伙伴系统初始化"
           data-author="" >
            <span class="post-title" title="linux 源代码分析5:伙伴系统初始化">linux 源代码分析5:伙伴系统初始化</span>
            <span class="post-date" title="2013-05-22 21:59:15">2013/05/22</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/06/03/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%906-Slab%E5%88%86%E9%85%8D%E5%99%A8/"
           data-tag="linux,内存管理,伙伴系统,Slab"
           data-author="" >
            <span class="post-title" title="linux 源代码分析6:Slab分配器">linux 源代码分析6:Slab分配器</span>
            <span class="post-date" title="2013-06-03 19:28:59">2013/06/03</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/06/05/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%907-Slab%E5%9D%97%E7%9A%84%E7%AE%A1%E7%90%86/"
           data-tag="linux,内存管理,伙伴系统,Slab"
           data-author="" >
            <span class="post-title" title="linux 源代码分析7:Slab块的管理">linux 源代码分析7:Slab块的管理</span>
            <span class="post-date" title="2013-06-05 20:56:05">2013/06/05</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/06/04/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%908-Slab%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D/"
           data-tag="linux,内存管理,伙伴系统,Slab"
           data-author="" >
            <span class="post-title" title="linux 源代码分析8:Slab内存分配">linux 源代码分析8:Slab内存分配</span>
            <span class="post-date" title="2013-06-04 19:47:29">2013/06/04</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/06/09/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%909-Slab%E5%86%85%E5%AD%98%E9%87%8A%E6%94%BE/"
           data-tag="linux,内存管理,伙伴系统,Slab"
           data-author="" >
            <span class="post-title" title="linux 源代码分析9:Slab内存释放">linux 源代码分析9:Slab内存释放</span>
            <span class="post-date" title="2013-06-09 20:17:42">2013/06/09</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/06/09/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%9010-slab%E9%80%9A%E7%94%A8%E9%95%BF%E5%BA%A6%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D/"
           data-tag="linux,内存管理,伙伴系统,Slab"
           data-author="" >
            <span class="post-title" title="linux 源代码分析10:slab通用长度内存分配">linux 源代码分析10:slab通用长度内存分配</span>
            <span class="post-date" title="2013-06-09 20:17:42">2013/06/09</span>
        </a>
        
        <a id="top" class="linux "
           href="/2013/06/12/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%9011-Slab%E5%88%9D%E5%A7%8B%E5%8C%96/"
           data-tag="linux,内存管理,伙伴系统,Slab"
           data-author="" >
            <span class="post-title" title="linux 源代码分析11:Slab初始化">linux 源代码分析11:Slab初始化</span>
            <span class="post-date" title="2013-06-12 19:43:06">2013/06/12</span>
        </a>
        
        <a id="top" class="区块链 "
           href="/2020/03/29/ok6410-u-boot-dm9000-%E9%A9%B1%E5%8A%A8%E8%A1%A5%E4%B8%81-patch/"
           data-tag=""
           data-author="" >
            <span class="post-title" title="ok6410 u-boot dm9000 驱动补丁 patch">ok6410 u-boot dm9000 驱动补丁 patch</span>
            <span class="post-date" title="2020-03-29 21:58:09">2020/03/29</span>
        </a>
        
        <a id="top" class="区块链 "
           href="/2020/03/29/eostoolkit-%E5%AE%89%E8%A3%85/"
           data-tag=""
           data-author="" >
            <span class="post-title" title="eostoolkit 安装">eostoolkit 安装</span>
            <span class="post-date" title="2020-03-29 21:58:09">2020/03/29</span>
        </a>
        
        <a id="top" class="linux "
           href="/2020/03/29/sdl2-%E5%92%8C-dmalloc-%E4%B8%8D%E5%85%BC%E5%AE%B9/"
           data-tag=""
           data-author="" >
            <span class="post-title" title="sdl2 和 dmalloc 不兼容">sdl2 和 dmalloc 不兼容</span>
            <span class="post-date" title="2020-03-29 21:58:09">2020/03/29</span>
        </a>
        
        <a id="top" class="区块链 "
           href="/2018/07/29/bitcoin-%E6%B5%8B%E8%AF%95%E7%BD%91%E7%BB%9C/"
           data-tag=""
           data-author="" >
            <span class="post-title" title="bitcoin 测试网络">bitcoin 测试网络</span>
            <span class="post-date" title="2018-07-29 20:50:06">2018/07/29</span>
        </a>
        
        <a id="top" class="区块链 "
           href="/2018/07/29/USDT%E9%92%B1%E5%8C%85%E5%BD%92%E9%9B%86/"
           data-tag=""
           data-author="" >
            <span class="post-title" title="USDT钱包归集">USDT钱包归集</span>
            <span class="post-date" title="2018-07-29 20:50:06">2018/07/29</span>
        </a>
        
        <a id="top" class="c++ "
           href="/2012/10/24/%E8%B0%83%E8%AF%95%E5%AE%8F-DPRINTF-DERROR-PERR/"
           data-tag="调试宏,DPRINTF,DERROR,PERR"
           data-author="" >
            <span class="post-title" title="调试宏 DPRINTF DERROR PERR">调试宏 DPRINTF DERROR PERR</span>
            <span class="post-date" title="2012-10-24 17:38:38">2012/10/24</span>
        </a>
        
        <a id="top" class="区块链 "
           href="/2018/08/29/%E6%AF%94%E7%89%B9%E5%B8%81%E5%AE%A2%E6%88%B7%E7%AB%AFbitcoind%E7%9A%84%E9%AB%98%E7%BA%A7%E7%94%A8%E6%B3%95/"
           data-tag=""
           data-author="" >
            <span class="post-title" title="比特币客户端bitcoind的高级用法">比特币客户端bitcoind的高级用法</span>
            <span class="post-date" title="2018-08-29 20:51:09">2018/08/29</span>
        </a>
        
        <a id="top" class="区块链 "
           href="/2016/11/23/geth%E7%A7%81%E6%9C%89%E7%BD%91%E7%BB%9C%E6%90%AD%E5%BB%BA/"
           data-tag="geth,私有网络搭建"
           data-author="" >
            <span class="post-title" title="geth私有网络搭建">geth私有网络搭建</span>
            <span class="post-date" title="2016-11-23 17:51:36">2016/11/23</span>
        </a>
        
        <a  class="react native "
           href="/2020/09/15/react-native-%E6%A0%B7%E5%BC%8F/"
           data-tag="react native,样式"
           data-author="" >
            <span class="post-title" title="react native 样式">react native 样式</span>
            <span class="post-date" title="2020-09-15 08:58:46">2020/09/15</span>
        </a>
        
        <a  class="c++ "
           href="/2020/09/15/c%E8%AF%AD%E8%A8%80-%E4%BA%8C%E5%88%86%E6%B3%95%E6%9F%A5%E6%89%BE/"
           data-tag="c语言,二分法查找"
           data-author="" >
            <span class="post-title" title="c语言 二分法查找">c语言 二分法查找</span>
            <span class="post-date" title="2020-09-15 08:51:53">2020/09/15</span>
        </a>
        
        <a  class="react native "
           href="/2020/05/19/code-push%E4%BD%BF%E7%94%A8%E8%AE%B0%E5%BD%95/"
           data-tag="code-push"
           data-author="" >
            <span class="post-title" title="code-push使用记录">code-push使用记录</span>
            <span class="post-date" title="2020-05-19 16:54:53">2020/05/19</span>
        </a>
        
        <a  class="c++ "
           href="/2018/09/15/%E4%BB%A5%E5%A4%AA%E5%9D%8Ac++%E7%89%88%E6%9C%ACrpc%E6%8E%A5%E5%8F%A3%E6%B7%BB%E5%8A%A0/"
           data-tag="以太坊,c++,rpc"
           data-author="" >
            <span class="post-title" title="以太坊c++版本rpc接口添加">以太坊c++版本rpc接口添加</span>
            <span class="post-date" title="2018-09-15 16:06:05">2018/09/15</span>
        </a>
        
        <a  class="c++ "
           href="/2011/04/28/gbk2312%E6%8B%BC%E9%9F%B3%E8%A1%A8-%E6%8C%89%E8%AF%8D%E9%A2%91%E6%8E%92%E5%A5%BD%E5%BA%8F%E7%9A%84/"
           data-tag="gbk2312，拼音表，排好"
           data-author="" >
            <span class="post-title" title="gbk2312拼音表 按词频排好序的">gbk2312拼音表 按词频排好序的</span>
            <span class="post-date" title="2011-04-28 11:21:00">2011/04/28</span>
        </a>
        
    </nav>
</div>
    </div>
    <div class="hide-list">
        <div class="semicircle">
            <div class="brackets first"><</div>
            <div class="brackets">&gt;</div>
        </div>
    </div>
</aside>
<div class="post">
    <div class="pjax">
        <article id="post-linux-3-4-10-内核内存管理源代码分析8-Slab内存分配" class="article article-type-post" itemscope itemprop="blogPost">
    
        <h1 class="article-title">linux 源代码分析8:Slab内存分配</h1>
    
    <div class="article-meta">
        
        <span class="top"><a>置顶</a></span>
        
        
        
        <span class="book">
            
                <a  data-rel="linux">linux</a>
            
        </span>
        
        
        <span class="tag">
            
            <a class="color1">linux</a>
            
            <a class="color5">内存管理</a>
            
            <a class="color5">伙伴系统</a>
            
            <a class="color5">Slab</a>
            
        </span>
        
    </div>
    <div class="article-meta">
        
        创建时间:<time class="date" title='更新时间: 2020-04-18 15:57:53'>2013-06-04 19:47</time>
        
    </div>
    <div class="article-meta">
        
        
        <span id="busuanzi_container_page_pv">
            阅读:<span id="busuanzi_value_page_pv">
                <span class="count-comment">
                    <span class="spinner">
                      <div class="cube1"></div>
                      <div class="cube2"></div>
                    </span>
                </span>
            </span>
        </span>
        
        
    </div>
    
    <div class="toc-ref">
    
        <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Slab内存分配"><span class="toc-text">Slab内存分配</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#kmem-cache-alloc函数"><span class="toc-text">kmem_cache_alloc函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#cache-alloc"><span class="toc-text">__cache_alloc</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#do-cache-alloc函数"><span class="toc-text">__do_cache_alloc函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#cache-alloc函数"><span class="toc-text">____cache_alloc函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#cache-alloc-refill函数"><span class="toc-text">cache_alloc_refill函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#cache-grow函数"><span class="toc-text">cache_grow函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#kmem-getpages函数"><span class="toc-text">kmem_getpages函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#alloc-slabmgmt函数"><span class="toc-text">alloc_slabmgmt函数</span></a></li></ol></li></ol>
    
<style>
    .left-col .switch-btn,
    .left-col .switch-area {
        display: none;
    }
    .toc-level-3 i,
    .toc-level-3 ol {
        display: none !important;
    }
</style>
</div>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="Slab内存分配"><a href="#Slab内存分配" class="headerlink" title="Slab内存分配"></a>Slab内存分配</h1><h2 id="kmem-cache-alloc函数"><a href="#kmem-cache-alloc函数" class="headerlink" title="kmem_cache_alloc函数"></a>kmem_cache_alloc函数</h2><pre><code>kmem_cache_alloc函数在一个特点slab缓存分配内存，在mm/slab.c中实现代码如下：
3764 void *kmem_cache_alloc(structkmem_cache *cachep, gfp_t flags)
3765 {
3766        void *ret = __cache_alloc(cachep, flags, __builtin_return_address(0));
3767
3768        trace_kmem_cache_alloc(_RET_IP_, ret,
3769                               obj_size(cachep), cachep-&gt;buffer_size, flags);
3770
3771        return ret;
3772 }

kmem_cache_alloc函数的关键是对__cache_alloc的调用。</code></pre><h2 id="cache-alloc"><a href="#cache-alloc" class="headerlink" title="__cache_alloc"></a>__cache_alloc</h2><pre><code>__cache_alloc在mm/slab.c中实现代码如下：
3592 static __always_inline void *
3593 __cache_alloc(struct kmem_cache*cachep, gfp_t flags, void *caller)
3594 {
3595        unsigned long save_flags;
3596        void *objp;
3597
3598        flags &amp;= gfp_allowed_mask;
3599
3600        lockdep_trace_alloc(flags);
3601
3602        if (slab_should_failslab(cachep, flags))
3603        return NULL;
3604
3605        cache_alloc_debugcheck_before(cachep, flags);
3606        local_irq_save(save_flags);
3607        objp = __do_cache_alloc(cachep, flags);
3608        local_irq_restore(save_flags);
3609        objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller);
3610        kmemleak_alloc_recursive(objp, obj_size(cachep), 1, cachep-&gt;flags,
3611                         flags);
3612        prefetchw(objp);
3613
3614        if (likely(objp))
3615        kmemcheck_slab_alloc(cachep,flags, objp, obj_size(cachep));
3616
3617        if (unlikely((flags &amp; __GFP_ZERO) &amp;&amp; objp))
3618        memset(objp, 0,obj_size(cachep));
3619
3620        return objp;
3621 }

3606行__cache_alloc函数中关闭了中断，3607调用__do_cache_alloc函数进行分配，3608行开启中断。
3612是预加载缓存的代码。
3617-3618行对__GFP_ZERO选项进行了处理，就是把分配的内存块初始化为0。
其他是关于kmemcheck和调试代码。</code></pre><h2 id="do-cache-alloc函数"><a href="#do-cache-alloc函数" class="headerlink" title="__do_cache_alloc函数"></a>__do_cache_alloc函数</h2><pre><code>__do_cache_alloc在mm/slab.c中实现代码如下：
3584 static __always_inline void *
3585 __do_cache_alloc(struct kmem_cache*cachep, gfp_t flags)
3586 {
3587        return ____cache_alloc(cachep, flags);
3588 }
__do_cache_alloc是直接对____cache_alloc的调用。</code></pre><h2 id="cache-alloc函数"><a href="#cache-alloc函数" class="headerlink" title="____cache_alloc函数"></a>____cache_alloc函数</h2><pre><code>____cache_alloc在mm/slab.c中实现代码如下：
3291 static inline void*____cache_alloc(struct kmem_cache *cachep, gfp_t flags)
3292 {
3293        void *objp;
3294        struct array_cache *ac;
3295
3296        check_irq_off();
3297
3298        ac = cpu_cache_get(cachep);
3299        if (likely(ac-&gt;avail)) {
3300        STATS_INC_ALLOCHIT(cachep);
3301        ac-&gt;touched = 1;
3302        objp =ac-&gt;entry[--ac-&gt;avail];
3303        } else {
3304        STATS_INC_ALLOCMISS(cachep);
3305        objp =cache_alloc_refill(cachep, flags);
3306                /*
3307         * the &apos;ac&apos; may be updated bycache_alloc_refill(),
3308         * and kmemleak_erase()requires its correct value.
3309         */
3310        ac = cpu_cache_get(cachep);
3311        }
3312        /*
3313 * To avoid a false negative, if anobject that is in one of the
3314 * per-CPU caches is leaked, we needto make sure kmemleak doesn&apos;t
3315 * treat the array pointers as areference to the object.
3316 */
3317        if (objp)
3318                kmemleak_erase(&amp;ac-&gt;entry[ac-&gt;avail]);
3319        return objp;
3320 }

____cache_alloc分两条路径进行分配，当前cpu的对象缓存不空，从当前cpu的缓存堆栈中弹出一个对象就可以了，如果缓存堆栈已经为空，要从三链表中的slab块中取出一批对象到对象缓存中，然后再从对象缓存中弹出一个对象。
3298获得当前cpu的对象缓存。
3300-3302行是对象缓存中不空的情况，3301行更新slab缓存堆栈的touched成员，表示slab缓存堆栈，被访问过。3302行从slab缓存堆栈弹出一个指针。
3305是当前cpu的对象缓存为空情况，调用cache_alloc_refill函数进行分配。</code></pre><h2 id="cache-alloc-refill函数"><a href="#cache-alloc-refill函数" class="headerlink" title="cache_alloc_refill函数"></a>cache_alloc_refill函数</h2><pre><code>cache_alloc_refill是slab内存分配中比较关键的函数，在mm/slab.c中实现代码如下：
3123 static void *cache_alloc_refill(structkmem_cache *cachep, gfp_t flags)
3124 {
3125        int batchcount;
3126        struct kmem_list3 *l3;
3127        struct array_cache *ac;
3128        int node;
3129
3130 retry:
3131        check_irq_off();
3132        node = numa_mem_id();
3133        ac = cpu_cache_get(cachep);
3134        batchcount = ac-&gt;batchcount;
3135        if (!ac-&gt;touched &amp;&amp; batchcount &gt; BATCHREFILL_LIMIT) {
3136        /*
3137         * If there was little recentactivity on this cache, then
3138         * perform only a partial refill.  Otherwise we could generate
3139         * refill bouncing.
3140         */
3141        batchcount =BATCHREFILL_LIMIT;
3142        }
3143        l3 = cachep-&gt;nodelists[node];
3144
3145        BUG_ON(ac-&gt;avail &gt; 0 || !l3);
3146        spin_lock(&amp;l3-&gt;list_lock);
3147
3148        /* See if we can refill from the shared array */
3149        if (l3-&gt;shared &amp;&amp; transfer_objects(ac, l3-&gt;shared,batchcount)) {
3150        l3-&gt;shared-&gt;touched = 1;
3151        goto alloc_done;
3152        }
3153
3154        while (batchcount &gt; 0) {
3155        struct list_head *entry;
3156        struct slab *slabp;
3157        /* Get slab alloc is to comefrom. */
3158        entry =l3-&gt;slabs_partial.next;
3159        if (entry ==&amp;l3-&gt;slabs_partial) {
3160                l3-&gt;free_touched =1;
3161                entry =l3-&gt;slabs_free.next;
3162                if (entry ==&amp;l3-&gt;slabs_free)
3163                        gotomust_grow;
3164        }
3165
3166        slabp = list_entry(entry,struct slab, list);
3167        check_slabp(cachep, slabp);
3168        check_spinlock_acquired(cachep);
3169
3170        /*
3171         * The slab was either onpartial or free list so
3172         * there must be at least oneobject available for
3173         * allocation.
3174         */
3175        BUG_ON(slabp-&gt;inuse &gt;=cachep-&gt;num);
3176
3177        while (slabp-&gt;inuse &lt;cachep-&gt;num &amp;&amp; batchcount--) {
3178                        STATS_INC_ALLOCED(cachep);
3179                        STATS_INC_ACTIVE(cachep);
3180                        STATS_SET_HIGH(cachep);
3181
3182                        ac-&gt;entry[ac-&gt;avail++] = slab_get_obj(cachep, slabp,
3183                                                            node);
3184        }
3185        check_slabp(cachep, slabp);
3186
3187        /* move slabp to correct slabplist: */
3188        list_del(&amp;slabp-&gt;list);
3189        if (slabp-&gt;free ==BUFCTL_END)
3190                        list_add(&amp;slabp-&gt;list, &amp;l3-&gt;slabs_full);
3191        else
3192                        list_add(&amp;slabp-&gt;list, &amp;l3-&gt;slabs_partial);
3193        }
3194
3195 must_grow:
3196        l3-&gt;free_objects -= ac-&gt;avail;
3197 alloc_done:
3198        spin_unlock(&amp;l3-&gt;list_lock);
3199
3200        if (unlikely(!ac-&gt;avail)) {
3201        int x;
3202        x = cache_grow(cachep, flags |GFP_THISNODE, node, NULL);
3203
3204        /* cache_grow can reenableinterrupts, then ac could change. */
3205        ac = cpu_cache_get(cachep);
3206        if (!x &amp;&amp; ac-&gt;avail== 0)       /* no objects in sight? abort*/
3207                return NULL;
3208
3209        if (!ac-&gt;avail)/* objects refilled by interrupt? */
3210                goto retry;
3211        }
3212        ac-&gt;touched = 1;
3213        return ac-&gt;entry[--ac-&gt;avail];
3214 }

当前cpu上的缓存堆栈为空的时候，会调用cache_alloc_refill从三链表中的slab块分配一批对象到缓存堆栈。cache_alloc_refill的关键步骤是找到当前cpu所在节点的三链表，从三链表的slabs_partial或slabs_free队列中的slab块中分配内存到slab缓存堆栈。如果三链表中也没有空闲对象的时候，需要从伙伴系统分配内存。
3132获得本地节点号
3133行获得本cpu的缓存堆栈
3134-3142计算一次填充的内存块数量
3143行获得节点三链表
3149-3152行，在三链表中包含一个共享缓存堆栈，如果三链表的共享标志位置位，则从三链表中的共享堆栈中移动一些空闲内存指针到需要填充的缓存堆栈（ac）
3154进入一个循环，直到填充到缓存堆栈的指针数量足够
3158-3164行从三链表中获取一个slab块，从代码中知道，会先获取三链表slabs_partial队列中的块，这样做的好处是可以尽可能的保持完全空闲的块，有利于内存回收。slabs_partial队列中的块是不完全空闲块，就是说块中有些部分已经分配出去有些还是空闲。如果slabs_partial队列为空，则会获取slabs_free队列中的slab块，如果slabs_free都为空，则跳到标号must_grow处执行，从伙伴系统分配内存。
3177-3185行，3182-3183行调用slab_get_obj从一个slab块中分配一块内存并把返回地址压入堆栈，slab_get_obj函数中后面分析。3185行调用check_slabp函数对slab块做些检查。
3188-3192行把slab块从三链表中原来的队列中移除，并依据slab块是否包含空闲空间加入slabs_full队列或slabs_partial队列。从代码中看到，slabp-&gt;free == BUFCTL_END时表示slab块已经不包含可以分配出去的空闲空间。
3200-3211行，3202调用cache_grow从伙伴系统分配空间，这时候是因为缓存堆栈和三链表都不包含空闲对象。因为刚才调用cache_grow函数，slab缓存的三链表指针可以已经改变，3205行重新获取一次。3206-3207如果没有从伙伴系统申请到内存并且三链表中没有可用的内存，则返回空指针。3209如果三链表中已经有可用的内存，则重试。
3212-3213设置缓存堆栈的访问标记，并且从堆栈中弹出指针并返回。</code></pre><h2 id="cache-grow函数"><a href="#cache-grow函数" class="headerlink" title="cache_grow函数"></a>cache_grow函数</h2><pre><code>当slab缓存的缓存内存数据不足时，也就是说缓存堆栈和三链表都不包含空闲对象时，会调用cache_grow函数，在cache_grow函数中向伙伴系统申请分配slab块，添加到三链表的空闲链表，cache_grow函数在mm/slab.c中实现代码如下：
2931static int cache_grow(struct kmem_cache *cachep,
2932        gfp_t flags, int nodeid, void*objp)
2933 {
2934        struct slab *slabp;
2935        size_t offset;
2936        gfp_t local_flags;
2937        struct kmem_list3 *l3;
2938
2939        /*
2940 * Be lazy and only check for validflags here,  keeping it out of the
2941 * critical path inkmem_cache_alloc().
2942 */
2943        BUG_ON(flags &amp; GFP_SLAB_BUG_MASK);
2944        local_flags = flags &amp;(GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK);
2945
2946        /* Take the l3 list lock to change the colour_next on this node */
2947        check_irq_off();
2948        l3 = cachep-&gt;nodelists[nodeid];
2949        spin_lock(&amp;l3-&gt;list_lock);
2950
2951        /* Get colour for the slab, and cal the next value. */
2952        offset = l3-&gt;colour_next;
2953        l3-&gt;colour_next++;
2954        if (l3-&gt;colour_next &gt;= cachep-&gt;colour)
2955        l3-&gt;colour_next = 0;
2956         spin_unlock(&amp;l3-&gt;list_lock);
2957
2958        offset *= cachep-&gt;colour_off;
2959
2960        if (local_flags &amp; __GFP_WAIT)
2961        local_irq_enable();
2962
2963        /*
2964 * The test for missing atomic flag isperformed here, rather than
2965 * the more obvious place, simply toreduce the critical path length
2966 * in kmem_cache_alloc(). If a calleris seriously mis-behaving they
2967 * will eventually be caught here(where it matters).
2968 */
2969        kmem_flagcheck(cachep, flags);
2970
2971        /*
2972 * Get mem for the objs.  Attempt to allocate a physical page from
2973 * &apos;nodeid&apos;.
2974 */
2975        if (!objp)
2976        objp = kmem_getpages(cachep,local_flags, nodeid);
2977        if (!objp)
2978        goto failed;
2979
2980        /* Get slab management. */
2981        slabp = alloc_slabmgmt(cachep, objp, offset,
2982                local_flags &amp;~GFP_CONSTRAINT_MASK, nodeid);
2983        if (!slabp)
2984        goto opps1;
2985
2986        slab_map_pages(cachep, slabp, objp);
2987
2988        cache_init_objs(cachep, slabp);
2989
2990        if (local_flags &amp; __GFP_WAIT)
2991        local_irq_disable();
2992        check_irq_off();
2993        spin_lock(&amp;l3-&gt;list_lock);
2994
2995        /* Make slab active. */
2996        list_add_tail(&amp;slabp-&gt;list, &amp;(l3-&gt;slabs_free));
2997        STATS_INC_GROWN(cachep);
2998        l3-&gt;free_objects += cachep-&gt;num;
2999        spin_unlock(&amp;l3-&gt;list_lock);
3000        return 1;
3001 opps1:
3002        kmem_freepages(cachep, objp);
3003 failed:
3004        if (local_flags &amp; __GFP_WAIT)
3005        local_irq_disable();
3006        return 0;
3007 }

cache_grow函数实现从伙伴系统分配内存，有三个比较重要的步骤，计算颜色偏移量，从伙伴系统分配内存块，构建slab块的控制数据。
2952-2958行的代码是对颜色的计算。
2975-2976行，如果传进的地址为空，则分配一块内存。这里节点号是由上层函数传进来的，在cache_alloc_refill-&gt;cache_grow的调用流程中，节点号的由numa_mem_id()函数返回，也就是正运行这段代码的cpu所在的节点的号码。
2981行是计算slab块的控制数据存放地址，控制数据存放地址有两种情况，一种是直接放在刚才申请到的内存块中，另外一种方法是另外申请一块内存来存放控制数据。
2981行调用函数slab_map_pages设置struct page的slab数据，这样可以根据逻辑地址管理找到管理这个逻辑地址的struct kmem_cache地址和struct slab地址（kfree函数中需要根据地址找到structkmem_cache地址），一页数据属于slab的时候，lru链表是没有作用的，正好把lru链表的next用来保存struct kmem_cache的地址，prev用来保struct slab地址。
2988行调用cache_init_objs初始化salb块的空闲编号列表。
2996行把slab块加入三链表的空闲链表。
2998行更新空闲对象计数。</code></pre><h2 id="kmem-getpages函数"><a href="#kmem-getpages函数" class="headerlink" title="kmem_getpages函数"></a>kmem_getpages函数</h2><pre><code>kmem_getpages在mm/slab.c中实现代码如下：
1787static void *kmem_getpages(struct kmem_cache *cachep, gfp_t flags, int nodeid)
1788 {
1789        struct page *page;
1790        int nr_pages;
1791        int i;
1792
1793 #ifndef CONFIG_MMU
1794        /*
1795 * Nommu uses slab&apos;s for processanonymous memory allocations, and thus
1796 * requires __GFP_COMP to properlyrefcount higher order allocations
1797 */
1798        flags |= __GFP_COMP;
1799 #endif
1800
1801        flags |= cachep-&gt;gfpflags;
1802        if (cachep-&gt;flags &amp; SLAB_RECLAIM_ACCOUNT)
1803        flags |= __GFP_RECLAIMABLE;
1804
1805        page = alloc_pages_exact_node(nodeid, flags | __GFP_NOTRACK,cachep-&gt;gfporder);
1806        if (!page) {
1807        if (!(flags &amp;__GFP_NOWARN) &amp;&amp; printk_ratelimit())
1808                        slab_out_of_memory(cachep, flags, nodeid);
1809        return NULL;
1810        }
1811
1812        nr_pages = (1 &lt;&lt; cachep-&gt;gfporder);
1813        if (cachep-&gt;flags &amp; SLAB_RECLAIM_ACCOUNT)
1814                add_zone_page_state(page_zone(page),
1815                NR_SLAB_RECLAIMABLE,nr_pages);
1816        else
1817                add_zone_page_state(page_zone(page),
1818                NR_SLAB_UNRECLAIMABLE,nr_pages);
1819        for (i = 0; i &lt; nr_pages; i++)
1820        __SetPageSlab(page + i);
1821
1822        if (kmemcheck_enabled &amp;&amp; !(cachep-&gt;flags &amp; SLAB_NOTRACK)){
1823        kmemcheck_alloc_shadow(page,cachep-&gt;gfporder, flags, nodeid);
1824
1825        if (cachep-&gt;ctor)
1826                kmemcheck_mark_uninitialized_pages(page,nr_pages);
1827        else
1828                        kmemcheck_mark_unallocated_pages(page, nr_pages);
1829        }
1830
1831        return page_address(page);
1832 }

Slab向伙伴系统申请内存工作真正是在kmem_getpages函数中完成的。
1805行调用alloc_pages_exact_node函数向伙伴系统申请内存。alloc_pages_exact_node是伙伴系统在一个特定节点中分配内存的函数。
1831行根据page结构转换为逻辑地址返回。</code></pre><h2 id="alloc-slabmgmt函数"><a href="#alloc-slabmgmt函数" class="headerlink" title="alloc_slabmgmt函数"></a>alloc_slabmgmt函数</h2><pre><code>slab块，也就是slab从伙伴申请分配到的块，由结构structslab描述，一slab块个struct slab存放在哪里呢？structslab的存放地址是由alloc_slabmgmt函数求得的，alloc_slabmgmt在mm/slab.c中实现代码如下：
2772 static struct slab*alloc_slabmgmt(struct kmem_cache *cachep, void *objp,
2773                           intcolour_off, gfp_t local_flags,
2774                           int nodeid)
2775 {
2776        struct slab *slabp;
2777
2778        if (OFF_SLAB(cachep)) {
2779        /* Slab management obj isoff-slab. */
2780        slabp =kmem_cache_alloc_node(cachep-&gt;slabp_cache,
2781                                              local_flags, nodeid);
2782        /*
2783         * If the first object in theslab is leaked (it&apos;s allocated
2784         * but no one has a referenceto it), we want to make sure
2785         * kmemleak does not treat the-&gt;s_mem pointer as a reference
2786         * to the object. Otherwise wewill not report the leak.
2787         */
2788                kmemleak_scan_area(&amp;slabp-&gt;list, sizeof(struct list_head),
2789                                   local_flags);
2790        if (!slabp)
2791                return NULL;
2792        } else {
2793        slabp = objp + colour_off;
2794        colour_off +=cachep-&gt;slab_size;
2795        }
2796        slabp-&gt;inuse = 0;
2797        slabp-&gt;colouroff = colour_off;
2798        slabp-&gt;s_mem = objp + colour_off;
2799        slabp-&gt;nodeid = nodeid;
2800        slabp-&gt;free = 0;
2801        return slabp;
2802 }

OFF_SLAB宏定义如下：
361 #defineOFF_SLAB (x)     ((x)-&gt;flags &amp;CFLGS_OFF_SLAB)
这样根据OFF_SLAB宏的返回值，如果structkmem_cache的成员flags的标志位是否设置CFLGS_OFF_SLAB来区分，struct slab是存放在从伙伴系统已经分配的块中还是另外申请空间用来存放struct slab结构。
2780行是申请单独的空间用来存放struct slab的情况，空间分配是调用kmem_cache_alloc_node函数实现的，在struct kmem_cache结构成员slabp_cache执行的slab缓存中分配。
2793-2794行struct slab是存放在slab块偏移colour_off处，为什么不存放在slab的开头？因为struct slab也可能被缓存，存放在偏移colour_off处比存放在slab块开头处发生缓存冲突的可能性小些。
2978行，综合2974行，slabp-&gt;s_mem的值是objp+cachep-&gt;slab_size。cachep-&gt;slab_size是缓存的slab的控制数据的总的长度，包含struct slab和空闲编号链表和对其因素。cachep-&gt;slab_size的值在kmem_cache_create中计算。</code></pre>
      
       <hr><span style="font-style: italic;color: gray;"> 转载请注明来源，欢迎对文章中的引用来源进行考证，欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论，也可以邮件至 ancjf@163.com </span>
    </div>
</article>


<p>
    <a  class="dashang" onclick="dashangToggle()">赏</a>
</p>


<div class="article_copyright">
    <p><span class="copy-title">文章标题:</span>linux 源代码分析8:Slab内存分配</p>
    
    <p><span class="copy-title">本文作者:</span><a  title="ancjf">ancjf</a></p>
    <p><span class="copy-title">发布时间:</span>2013-06-04, 19:47:29</p>
    <p><span class="copy-title">最后更新:</span>2020-04-18, 15:57:53</p>
    <span class="copy-title">原始链接:</span><a class="post-url" href="/2013/06/04/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%908-Slab%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D/" title="linux 源代码分析8:Slab内存分配">http://ancjf.com/2013/06/04/linux-3-4-10-%E5%86%85%E6%A0%B8%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86%E6%BA%90%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%908-Slab%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D/</a>
    <p>
        <span class="copy-title">版权声明:</span><i class="fa fa-creative-commons"></i> <a rel="license noopener" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" title="CC BY-NC-SA 4.0 International" target = "_blank">"署名-非商用-相同方式共享 4.0"</a> 转载请保留原文链接及作者。
    </p>
</div>





    




    </div>
    <div class="copyright">
        <p class="footer-entry">©2016-2019 Yelog</p>
<p class="footer-entry">Built with <a href="https://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/yelog/hexo-theme-3-hexo" target="_blank">3-hexo</a> theme</p>

    </div>
    <div class="full-toc">
        <button class="full"><span class="min "></span></button>
<button class="post-toc-menu"><span class="post-toc-menu-icons"></span></button>
<div class="post-toc"><span class="post-toc-title">目录</span>
    <div class="post-toc-content">

    </div>
</div>
<a class="" id="rocket" ></a>

    </div>
</div>
<div class="acParent"></div>

<div class="hide_box" onclick="dashangToggle()"></div>
<div class="shang_box">
    <a class="shang_close"  onclick="dashangToggle()">×</a>
    <div class="shang_tit">
        <p>喜欢就点赞,疼爱就打赏</p>
    </div>
    <div class="shang_payimg">
        <div class="pay_img">
            <img src="/img/alipay.jpg" class="alipay" title="扫码支持">
            <img src="/img/weixin.jpg" class="weixin" title="扫码支持">
        </div>
    </div>
    <div class="shang_payselect">
        <span><label><input type="radio" name="pay" checked value="alipay">支付宝</label></span><span><label><input type="radio" name="pay" value="weixin">微信</label></span>
    </div>
</div>


</body>
<script src="/js/jquery.pjax.js?v=1.0.1" ></script>

<script src="/js/script.js?v=1.0.1" ></script>
<script>
    var img_resize = 'default';
    /*作者、标签的自动补全*/
    $(function () {
        $('.search').AutoComplete({
            'data': ['#linux','#内存管理','#伙伴系统','#内存分配','#内存释放','#伙伴系统初始化','#Slab','#EOS','#节点','#数据备份','#c语言','#二分法查找','#geth','#私有网络搭建','#以太坊','#c++','#rpc','#code-push','#react native','#样式','#调试宏','#DPRINTF','#DERROR','#PERR','#gbk2312，拼音表，排好',],
            'itemHeight': 20,
            'width': 418
        }).AutoComplete('show');
    })
    function initArticle() {
        /*渲染对应的表格样式*/
        
            $(".post .pjax table").addClass("green_title");
        

        /*渲染打赏样式*/
        
        $("input[name=pay]").on("click", function () {
            if($("input[name=pay]:checked").val()=="weixin"){
                $(".shang_box .shang_payimg .pay_img").addClass("weixin_img");
            } else {
                $(".shang_box .shang_payimg .pay_img").removeClass("weixin_img");
            }
        })
        

        /*高亮代码块行号*/
        
        $('pre code').each(function(){
            var lines = $(this).text().split('\n').length - 1, widther='';
            if (lines>99) {
                widther = 'widther'
            }
            var $numbering = $('<ul/>').addClass('pre-numbering ' + widther).attr("unselectable","on");
            $(this).addClass('has-numbering ' + widther)
                    .parent()
                    .append($numbering);
            for(var i=1;i<=lines;i++){
                $numbering.append($('<li/>').text(i));
            }
        });
        

        /*访问数量*/
        
        $.getScript("//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js");
        

        /*代码高亮，行号对齐*/
        $('.pre-numbering').css('line-height',$('.has-numbering').css('line-height'));

        
        
    }

    /*打赏页面隐藏与展示*/
    
    function dashangToggle() {
        $(".shang_box").fadeToggle();
        $(".hide_box").fadeToggle();
    }
    

</script>

<!--加入行号的高亮代码块样式-->

<style>
    pre{
        position: relative;
        margin-bottom: 24px;
        border-radius: 10px;
        border: 1px solid #e2dede;
        background: #FFF;
        overflow: hidden;
    }
    code.has-numbering{
        margin-left: 30px;
    }
    code.has-numbering.widther{
        margin-left: 35px;
    }
    .pre-numbering{
        margin: 0px;
        position: absolute;
        top: 0;
        left: 0;
        width: 20px;
        padding: 0.5em 3px 0.7em 5px;
        border-right: 1px solid #C3CCD0;
        text-align: right;
        color: #AAA;
        background-color: #fafafa;
    }
    .pre-numbering.widther {
        width: 35px;
    }
</style>

<!--自定义样式设置-->
<style>
    
    
    .nav {
        width: 542px;
    }
    .nav.fullscreen {
        margin-left: -542px;
    }
    .nav-left {
        width: 120px;
    }
    
    
    @media screen and (max-width: 1468px) {
        .nav {
            width: 492px;
        }
        .nav.fullscreen {
            margin-left: -492px;
        }
        .nav-left {
            width: 100px;
        }
    }
    
    
    @media screen and (max-width: 1024px) {
        .nav {
            width: 492px;
            margin-left: -492px
        }
        .nav.fullscreen {
            margin-left: 0;
        }
        .nav .hide-list.fullscreen {
            left: 492px
        }
    }
    
    @media screen and (max-width: 426px) {
        .nav {
            width: 100%;
        }
        .nav-left {
            width: 100%;
        }
    }
    
    
    .nav-right .title-list nav a .post-title, .nav-right .title-list #local-search-result a .post-title {
        color: #383636;
    }
    
    
    .nav-right .title-list nav a .post-date, .nav-right .title-list #local-search-result a .post-date {
        color: #5e5e5f;
    }
    
    
    .nav-right nav a.hover, #local-search-result a.hover{
        background-color: #e2e0e0;
    }
    
    

    /*列表样式*/
    
    .post .pjax article .article-entry>ol, .post .pjax article .article-entry>ul, .post .pjax article>ol, .post .pjax article>ul{
        border: #e2dede solid 1px;
        border-radius: 10px;
        padding: 10px 32px 10px 56px;
    }
    .post .pjax article .article-entry li>ol, .post .pjax article .article-entry li>ul,.post .pjax article li>ol, .post .pjax article li>ul{
        padding-top: 5px;
        padding-bottom: 5px;
    }
    .post .pjax article .article-entry>ol>li, .post .pjax article .article-entry>ul>li,.post .pjax article>ol>li, .post .pjax article>ul>li{
        margin-bottom: auto;
        margin-left: auto;
    }
    .post .pjax article .article-entry li>ol>li, .post .pjax article .article-entry li>ul>li,.post .pjax article li>ol>li, .post .pjax article li>ul>li{
        margin-bottom: auto;
        margin-left: auto;
    }
    

    /* 背景图样式 */
    
    


    /*引用块样式*/
    

    /*文章列表背景图*/
    
    .nav-right:before {
        content: ' ';
        display: block;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        opacity: 0.3;
        background: url("https://i.loli.net/2019/07/22/5d3521411f3f169375.png");
        background-repeat: no-repeat;
        background-position: 50% 0;
        -ms-background-size: cover;
        -o-background-size: cover;
        -moz-background-size: cover;
        -webkit-background-size: cover;
        background-size: cover;
    }
    

    
</style>







</html>
